<?php
function db_get_number_of_visa($numberVisa)
{
	$html=null;
	for ($i=1;$i<=10;$i++)
	{
		$tam=$i.' Applications';
		if($numberVisa == $tam)
		{			
			$html.='<option selected="selected" value="'.$i.' Applications">'.$i.' Applications</option>';
		}	
		else
		{
			$html.='<option  value="'.$i.' Applications">'.$i.' Applications</option>';
		}
	}
	echo $html;
}

function db_get_type_of_visa($typeVisa)
{
	$html=null;
	$purpost = get_option("setting_update_type_of_visa");
	//print_r($purpost);
	$purpost = explode(",", $purpost);
	$html.='<option value="">Select</option>';
	foreach ($purpost as $value) 
	{
		if($value==$typeVisa)
		{
			$html.='<option selected="selected" value="'.$value.'">'.$value.'</option>';
		}
		else 
		{
			$html.='<option value="'.$value.'">'.$value.'</option>';
		}
	}
		
	echo $html;
}

function db_purpose_of_visit($myvalue)
{
	$html=null;
	$purpost = get_option("setting_update_purpose_of_vist");
	//print_r($purpost);
	$purpost = explode(",", $purpost);
	$html.='<option value="">Select</option>';
	foreach ($purpost as $value) 
	{
		if($value==$myvalue)
		{
			$html.='<option selected="selected" value="'.$value.'">'.$value.'</option>';
		}
		else 
		{
			$html.='<option value="'.$value.'">'.$value.'</option>';
		}
	}
		
	echo $html;
}

function db_get_arrival_airport($myvalue)
{
	$html=null;
	$airport = get_option("setting_update_airport");
	$airport = explode(",", $airport);
	$html.='<option value="">Select</option>';
	foreach ($airport as $value) 
	{
		if($value==$myvalue)
		{
			$html.='<option selected="selected" value="'.$value.'">'.$value.'</option>';
		}
		else 
			$html.='<option value="'.$value.'">'.$value.'</option>';
	}	
	echo $html;
}

function db_processing_time($value)
{
	$html=null;
	if($value == "Normal")
		$html.='<option selected="selected" value="Normal">Normal (Guaranteed 2 working days)</option>';
	else 	
		$html.='<option value="Normal">Normal (Guaranteed 2 working days)</option>';
		
	if($value == "Urgent")	
		$html.='<option selected="selected" value="Urgent">Urgent (Guaranteed 1 working day)</option>';
	else 
		$html.='<option value="Urgent">Urgent (Guaranteed 1 working day)</option>';
	if($value == "Super urgent")		
		$html.='<option selected="selected" value="Super urgent">Super urgent (4 working hours )</option>';
	else 
		$html.='<option value="Super urgent">Super urgent (4 working hours )</option>';
	echo $html;
}

function db_get_deposit($type)
{
	$list_tour_type = db_get_list_tour_type();
	$flag = 0;
	foreach ($list_tour_type as $key=>$value) 
	{			
		if($key==$type)
		{
			$deposit = get_option("deposit_name_".$type);
			$flag = $deposit;
			return $deposit;			
		}
		//else 
			//return 0;
	}
	if($flag==0)
		return $flag;
}

function db_get_deposit_hotel($value)
{
	//print_r($value);
	$flag = 0;
	$from_list = db_select_all_data("hotel_price");
	foreach ($from_list as $val) 
	{
		if($value==$val->typeroom)
		{
			$deposit = get_option("hotel_deposit_name_".$val->ID);
			$flag = $deposit;
			return $deposit;
		}
	}
	if($flag==0)
		return $flag;
}

##+++++++++++++++++++++ DESTINATION +++++++++++++++++++++++++++++++++++++++
function db_insert_destination_from($_POST)
{
	global $wpdb;
	$table = $wpdb->prefix.'destination_from';
	$data = array(		
		'destinationFrom'	  	=> $_POST['des_from_insert']	
	);
	$wpdb->insert($table, $data);
}

function db_update_visa($_POST,$agentID)
{
	$numberVisa 		=$_POST['update_numberVisa'];
	$typeVisa 			=$_POST['update_typeVisa'];
	$purposeVisa 		=$_POST['update_purpose'];
	$processingTime 	=$_POST['update_processing'];
	$dateArrival 		=$_POST['update_yr_date_arrival'].'-'.$_POST['update_mo_date_arrival'].'-'.$_POST['update_dy_date_arrival'].' 00:00:00';
	$dateExit			=$_POST['update_yr_date_exit'].'-'.$_POST['update_mo_date_exit'].'-'.$_POST['update_dy_date_exit'].' 00:00:00';
	$arrivalAirport		=$_POST['update_arrivalAirport'];
	$flightNumber		=$_POST['update_flight_number'];
	
	global $wpdb;
	$table = $wpdb->prefix.'visas';
		
	$query = "UPDATE $table
		SET numberVisa 	= '".$numberVisa."',
		typeVisa		= '".$typeVisa."',
		purposeVisa		= '".$purposeVisa."',
		processingTime  = '".$processingTime."',
		dateArrival		= '".$dateArrival."',
		dateExit		= '".$dateExit."',
		arrivalAirport	= '".$arrivalAirport."',
		flightNumber	= '".$flightNumber."'			
		WHERE ID = $agentID
	";
	$wpdb->query($query);
}

function db_update_payment_status($paystatus,$payid)
{
	global $wpdb;
	$table = $wpdb->prefix.'payments';
		
	$query = "UPDATE $table
		SET paymentStatus = '".$paystatus."'			
		WHERE ID = $payid
	";
	$wpdb->query($query);
}


function db_update_guest($name,$pass,$customerID)
{
	global $wpdb;
	$table = $wpdb->prefix.'customers';
		
	$query = "UPDATE $table
		SET customerName = '".$name."'			
		WHERE ID = $customerID
	";
	$wpdb->query($query);
	
	$table2 = $wpdb->prefix.'passports';
		
	$query = "UPDATE $table2
		SET passportNumber = '".$pass."'			
		WHERE customerID = $customerID
	";
	$wpdb->query($query);
}

function db_update_destination_from($_POST)
{
	global $wpdb;
	$table = $wpdb->prefix.'destination_from';
	$des	= $_POST['des_from_insert'];
	$desID  = $_POST['des_from_update_ID'];
	
	$query = "UPDATE $table
		SET destinationFrom = '".$des."'
		WHERE ID = $desID
	";
	$wpdb->query($query);
}

function db_insert_destination_to($_POST)
{
	global $wpdb;
	$table = $wpdb->prefix.'destination_to';
	$data = array(		
		'destinationTo'	  	=> $_POST['des_to_insert']	
	);
	$wpdb->insert($table, $data);
}

function db_update_destination_to($_POST)
{
	global $wpdb;
	$table = $wpdb->prefix.'destination_to';
	$des	= $_POST['des_to_insert'];
	$desID  = $_POST['des_to_update_ID'];
	
	$query = "UPDATE $table
		SET destinationTo = '".$des."'
		WHERE ID = $desID
	";
	$wpdb->query($query);
}

##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function db_get_list_tour_type()
{
	$payment = array(
	'standard'		=> 'Standard',
	'superior'		=> 'Superior',
	'firstclass'	=> 'First Class',
	'deluxe'		=> 'Deluxe'		
	);
	return $payment;
}

##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function db_get_list_payment_status()
{
	$payment = array(
	'Pending'		=> 'Pending',
	'Processing'	=> 'Processing',
	'Verify'		=> 'Verify',
	'Completed'			=> 'Completed'		
	);
	return $payment;
}


##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function db_insert_payments($data,$date)
{
	global $wpdb;	
	$table = $wpdb->prefix.'payments';	
	$wpdb->insert($table, $data);
	$paymentID = db_get_ItemID_by_date($table,$date);
	return $paymentID;
}

##++++++++++++++++++++++++++++++++ ORDERS PROCESS ++++++++++++++++++++++++++++++++++
function db_insert_orders($data,$date)
{
	global $wpdb;	
	$table = $wpdb->prefix.'orders';	
	$wpdb->insert($table, $data);
	$orderID = db_get_ItemID_by_date($table,$date);
	return $orderID;
}

##++++++++++++++++++++++++++++++++ HOTEL PROCESS ++++++++++++++++++++++++++++++++++
function db_insert_hotels($data,$date)
{
	global $wpdb;	
	$table = $wpdb->prefix.'tours';	
	$wpdb->insert($table, $data);
	$hotelID = db_get_ItemID_by_date($table,$date);
	return $hotelID;
}

##+++++++++++++++++++++++++++++++ TOURS PROCESS ++++++++++++++++++++++++++++++++++++++++++
function db_get_ItemID_by_date($table,$date)
{
	global $wpdb;	
	$sql ="SELECT ID FROM $table WHERE date='".$date."'";
	$result = $wpdb->get_results($sql,OBJECT);
	return $result[0]->ID;
}

function db_insert_tours($data,$date)
{
	global $wpdb;	
	$table = $wpdb->prefix.'tours';	
	$wpdb->insert($table, $data);
	$tourID = db_get_ItemID_by_date($table,$date);
	return $tourID;
}

function db_insert_data($table,$data,$date)
{
	global $wpdb;	
	$table = $wpdb->prefix.$table;	
	$wpdb->insert($table, $data);
	$tourID = db_get_ItemID_by_date($table,$date);
	return $tourID;
}
##++++++++++++++++++++++++++++ CUSTOMER PROCESS+++++++++++++++++++++++++++++++++++++++++++++
function db_insert_customer($data,$date)
{
	global $wpdb;	
	$table = $wpdb->prefix.'customers';	
	$wpdb->insert($table, $data);
	$customerID = db_get_ItemID_by_date($table,$date);
	return $customerID;
}


##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function db_update_tour_price_table($_POST)
{
	global $wpdb;
	$table = $wpdb->prefix.'tour_price';
	
		$tourID				= $_POST['tourID_hidden'];
		$travelinparty  	= $_POST['travel-in-party-of'];
		$tandard		  	= $_POST['standard'];
		$superior		  	= $_POST['superior'];
		$firstclass		  	= $_POST['first-class'];
		$deluxe 		 	= $_POST['deluxe'];
		$tourid             = $_POST['price_table_tour2'];
	
	$query = "UPDATE $table
			SET travelinparty='".$travelinparty."',
			standard 		= $tandard,
			superior 		= $superior,			
			firstclass		= $firstclass,
			deluxe			= $deluxe,
			tourID			= $tourid
			WHERE ID = $tourID
	";
	$wpdb->query($query);
}

function db_insert_tour_price_table($_POST)
{
	global $wpdb;
	$table = $wpdb->prefix.'tour_price';
	$data = array(
		'travelinparty'  	=> $_POST['travel-in-party-of'],
		'standard'		  	=> $_POST['standard'],
		'superior'		  	=> $_POST['superior'],
		'firstclass'	  	=> $_POST['first-class'],
		'deluxe' 		 	=> $_POST['deluxe'],
		'tourID'			=> $_POST['price_table_tour']
	);
	$wpdb->insert($table, $data);
}

##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function db_insert_hotel_price_table($_POST)
{
	global $wpdb;
	$table = $wpdb->prefix.'hotel_price';
	$data = array(
		'typeroom'  		=> $_POST['typeroom'],
		'max'		  		=> $_POST['max'],
		'totalofroom'		=> $_POST['totalofroom'],
		'roomempty'	  		=> $_POST['roomempty'],
		'ratefornight' 		=> $_POST['ratefornight'],
		'hotelID'			=> $_POST['price_table_hotel']
	);
	$wpdb->insert($table, $data);
}

##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function db_update_hotel_price_table($_POST)
{
	global $wpdb;
	$table = $wpdb->prefix.'hotel_price';
		$hotelID			= $_POST['hotelID_hidden'];
		$typeroom  	    	= $_POST['typeroom'];
		$max		  		= $_POST['max'];
		$totalofroom		= $_POST['totalofroom'];
		$roomempty	  		= $_POST['roomempty'];
		$ratefornight 		= $_POST['ratefornight'];
		$hoteid				= $_POST['price_table_hotel2'];
	$query = "
			UPDATE $table
			SET typeroom		= '".$typeroom."',
				max				= '".$max."',
				totalofroom		= $totalofroom,
				roomempty		= $roomempty,
				ratefornight	= '".$ratefornight."',
				hotelID			=  $hoteid
			WHERE ID	= $hotelID	
	";
	$wpdb->query($query);
		
}
##++++++++++++++++++++++++++ DELETE +++++++++++++++++++++++++++++++++++++++++++++++
function db_delete_item_price_by_id($id,$table)
{
	global $wpdb;
	$table = $wpdb->prefix.$table;
	$query = "DELETE FROM $table WHERE ID=$id";
	$wpdb->query($query);
}

function db_delete_ticket_by_id($ticket,$customerid)
{
	global $wpdb;	
	db_delete_item_price_by_id($ticket, "tickets");
	db_delete_item_price_by_id($customerid, "customers");
}

function db_delete_agents_by_id($ticket,$customerid)
{
	global $wpdb;	
	db_delete_item_price_by_id($ticket, "agents");
	db_delete_item_price_by_id($customerid, "customers");
}

function db_delete_visas_by_id($visaid,$customerid)
{
	global $wpdb;	
	db_delete_item_price_by_id($visaid, "visas");
	
	$list_guest = db_select_data_by_int("customers", "guestParent", $customerid);
	foreach ($list_guest as $value) 
	{
		db_delete_item_price_by_id($value->ID, "customers");	
	}	
}

function db_delete_order_tour($del)
{
	//$del = orderID
	$orderID 		= $del;
	$orders = db_select_data_by_int("orders", "ID", $orderID);
		
	$customerID		= $orders[0]->customerID;
	$tourID 		= $orders[0]->itemID;
	$paymentID 		= $orders[0]->paymentID;
	
	db_delete_item_price_by_id($paymentID,"payments");
	db_delete_item_price_by_id($tourID,"tours");
	db_delete_item_price_by_id($customerID,"customers");
	db_delete_item_price_by_id($orderID,"orders");
}
function db_delete_order_hotel($del)
{
	//$del = orderID
	$orderID 		= $del;
	$orders = db_select_data_by_int("orders", "ID", $orderID);
		
	$customerID		= $orders[0]->customerID;
	$hotelID 		= $orders[0]->itemID;
	$paymentID 		= $orders[0]->paymentID;
	
	db_delete_item_price_by_id($paymentID,"payments");
	db_delete_item_price_by_id($hotelID,"hotels");
	db_delete_item_price_by_id($customerID,"customers");
	db_delete_item_price_by_id($orderID,"orders");
}

##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function db_select_all_data($table)
{
		global $wpdb;
		$table = $wpdb->prefix.$table;
		$query	= "SELECT * FROM $table";
		$result	= $wpdb->get_results($query, OBJECT);
		if($result)
			return $result;
		else 
			return false;	
}

##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function db_select_all_data_order($table)
{
		global $wpdb;
		$table = $wpdb->prefix.$table;
		$query	= "SELECT * FROM $table ORDER BY ID DESC";
		$result	= $wpdb->get_results($query, OBJECT);
		if($result)
			return $result;
		else 
			return false;	
}

##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function db_select_all_data_by_tourID($table,$tourID)
{
		global $wpdb;
		$table = $wpdb->prefix.$table;
		$query	= "SELECT * FROM $table WHERE tourID=$tourID";
		$result	= $wpdb->get_results($query, OBJECT);
		if($result)
			return $result;
		else 
			return false;	
}
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function db_select_all_data_by_hotelID($table,$hotelID)
{
		global $wpdb;
		$table = $wpdb->prefix.$table;
		$query	= "SELECT * FROM $table WHERE hotelID=$hotelID";
		$result	= $wpdb->get_results($query, OBJECT);
		if($result)
			return $result;
		else 
			return false;	
}

##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function db_select_all_data_where_char($table,$key,$value)
{
		global $wpdb;
		$table = $wpdb->prefix.$table;
		$query	= "SELECT * FROM $table WHERE $key='".$value."' ORDER BY ID DESC";
		$result	= $wpdb->get_results($query, OBJECT);
		if($result)
			return $result;
		else 
			return false;	
}

##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function db_select_all_data_limit($table,$start,$length,$type)
{
		global $wpdb;
		$table = $wpdb->prefix.$table;
		$query	= "SELECT * FROM $table WHERE orderType=$type ORDER BY ID DESC LIMIT $start,$length";
		$result	= $wpdb->get_results($query, OBJECT);
		if($result)
			return $result;
		else 
			return false;	
}

##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function db_select_all_data_visa_limit($table,$start,$length)
{
		global $wpdb;
		$table = $wpdb->prefix.$table;
		$query	= "SELECT * FROM $table ORDER BY ID DESC LIMIT $start,$length";
		$result	= $wpdb->get_results($query, OBJECT);
		if($result)
			return $result;
		else 
			return false;	
}
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function db_select_all_data_limit_custom($table,$start,$length,$keytype,$type)
{
		global $wpdb;
		$table = $wpdb->prefix.$table;
		
		if($type!=-1)
		{
			$query	= "SELECT * FROM $table WHERE $keytype='".$type."' ORDER BY ID DESC LIMIT $start,$length";
		}
		else 
		{
			$query	= "SELECT * FROM $table ORDER BY ID DESC LIMIT $start,$length";
		}		
		$result	= $wpdb->get_results($query, OBJECT);
		if($result)
			return $result;
		else 
			return false;	
}

##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function db_select_data_by_int($table,$key,$value)
{
		global $wpdb;
		$table = $wpdb->prefix.$table;
		
		$query	= "SELECT * FROM $table
				   WHERE $key=$value	
				";
		$result	= $wpdb->get_results($query, OBJECT);
		if($result)
			return $result;
		else 
			return false;	
}
##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function db_select_data_by_char($table,$key,$value)
{
		global $wpdb;
		$table = $wpdb->prefix.$table;
		
		$query	= "SELECT * FROM $table
				   WHERE $key='".$value."'	
				";
		$result	= $wpdb->get_results($query, OBJECT);
		if($result)
			return $result;
		else 
			return false;	
}
function db_select_data_by_char_two($table,$key,$value,$key2,$value2)
{
		global $wpdb;
		$table = $wpdb->prefix.$table;
		
		$query	= "SELECT * FROM $table
				   WHERE $key='".$value."' AND $key2=$value2 	
				";
		$result	= $wpdb->get_results($query, OBJECT);
		if($result)
			return $result;
		else 
			return false;	
}

##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function db_table_get_id_by($table,$ID)
{
		global $wpdb;
		$table = $wpdb->prefix.$table;
		
		$query	= "SELECT * FROM $table
				   WHERE ID=".$ID."	
				";
		$result	= $wpdb->get_results($query, OBJECT);
		if($result)
			return $result;
		else 
			return false;
}

##--------------------- UPDATE ----------------------------
function db_update_table_field_id($ID,$field,$value)
{
	global $wpdb;
	$table = $wpdb->prefix.'payments';	
	$query = "UPDATE $table
		SET $field = '".$value."'
		WHERE ID = $ID
	";
	$wpdb->query($query);
}

function db_update_payment_after($ID,$payment_status,$payment_gross)
{
	global $wpdb;
	$table = $wpdb->prefix.'payments';
		
	$query = "UPDATE $table	
		SET paymentCurrent  = '".$payment_gross."',
			paymentStatus 	= '".$payment_status."'							
		WHERE ID 			= $ID
	";	
	$wpdb->query($query);
}

function db_update_customer($customerID,$params)
{
	//print_r($params);
	//print_r($customerID);
	global $wpdb;
	$table = $wpdb->prefix.'customers';	
	$query = "UPDATE $table
		SET customerName 	= '".$params['name']."',
		customerAddress 	= '".$params['address']."',
		customerEmail		= '".$params['email']."',
		customerPhone		= '".$params['tel']."'
		WHERE ID 			= $customerID
	";
	
	//print_r($query);
	$wpdb->query($query);
}

function db_update_company($companyID,$params)
{	
	global $wpdb;
	$table = $wpdb->prefix.'agents';	
	$query = "UPDATE $table
		SET companyName 	= '".$params['companyname']."',
		companyAddress 	= '".$params['companyaddress']."',
		companyEmail		= '".$params['companyemail']."',
		companyPhone		= '".$params['companytel']."',
		companyFax			= '".$params['companyfax']."'
		WHERE ID 			= $companyID
	";
	
	//print_r($query);
	$wpdb->query($query);
}


function db_update_ticket($ticketID)
{
	
			$transport	= $_POST['update_transport_ticket'];
			$goway		= $_POST['update_away'];
			$gofrom		= $_POST['update_from'];
			$goto		= $_POST['update_to'];
			$checkIn	= $_POST['update_INyr'].'-'.$_POST['update_INmo'].'-'.$_POST['update_INdy'].' 00:00:00';
 			$timeIn		= $_POST['update_time_in_ticket'];
			$checkOut	= $_POST['update_OUTyr'].'-'.$_POST['update_OUTmo'].'-'.$_POST['update_OUTdy'].' 00:00:00';
 			$timeOut	= $_POST['update_time_out_ticket'];
			$adults		= $_POST['update_adults'];
			$childrent	= $_POST['update_childrent'];
			$infant		= $_POST['update_infant'];
			$onday		= $_POST['update_book_on_date'];
			$status		= $_POST['update_payment'];
	
	//print_r($params);
	global $wpdb;
	$table = $wpdb->prefix.'tickets';	
	$query = "UPDATE $table	
			SET	
			transport		= '".$transport."',
			goway			= '".$goway."',
			gofrom		= '".$gofrom."',
			goto			= '".$goto."',
			checkIn		= '".$checkIn."',
 			timeIn		= '".$timeIn."',
			checkOut		= '".$checkOut."',
 			timeOut		= '".$timeOut."',
			adults		= '".$adults."',
			childrent		= '".$childrent."',
			infant		= '".$infant."',
			onday			= '".$onday."',
			status		= '".$status."'
			
		WHERE ID 			= $ticketID
	";	
	$wpdb->query($query);
}

function db_update_order($orders)
{
	global $wpdb;
	$table = $wpdb->prefix.'orders';
	$ID = $orders['ID'];	
	$query = "UPDATE $table
		SET orderStatus 	= '".$orders['orderStatus']."'		
		WHERE ID 			= $ID
	";
	
	//print_r($query);
	$wpdb->query($query);
}

function db_update_tours($tours)
{
	global $wpdb;
	$table = $wpdb->prefix.'tours';
	$ID = $tours['ID'];
	
	$query = "UPDATE $table
		SET tourID 			= '".$tours['tourID']."',
			travelInpartof	= '".$tours['travelInpartof']."',
			typeTour		= '".$tours['typeTour']."',
			proposeDate		= '".$tours['proposeDate']."'			
		WHERE ID 			= $ID
	";	
	$wpdb->query($query);
}

function db_update_hotels($hotelA)
{
	global $wpdb;
	$table = $wpdb->prefix.'hotels';
	$ID = $hotelA['ID'];
	$ht =$hotelA['hotelID'];
	
	$query = "UPDATE $table
		SET hotelID 	= '".$ht."',
			typeRoom	= '".$hotelA['typeRoom']."',
			checkIn		= '".$hotelA['checkIn']."',
			checkOUT	= '".$hotelA['checkOUT']."'			
		WHERE ID 		= $ID
	";	
	$wpdb->query($query);
}

function db_update_ticket_by_id($table,$key,$value,$ID,$type)
{
	global $wpdb;
	$table = $wpdb->prefix.$table;
	if($type==1)  //kieu int 0 kiey char
	{
		$query = "UPDATE $table
			SET $key	= $value					
			WHERE ID 	= $ID
		";
	}
	else 
	{
		$query = "UPDATE $table
			SET $key	= '".$value."'					
			WHERE ID 			= $ID
		";
	}
	//print_r($query);
	$wpdb->query($query);
}

function db_update_payment($payments)
{
	global $wpdb;
	$table = $wpdb->prefix.'payments';
	$ID = $payments['ID'];	
	$query = "UPDATE $table
		SET paymentStatus 	= '".$payments['paymentStatus']."'					
		WHERE ID 			= $ID
	";
	
	//print_r($query);
	$wpdb->query($query);
}

function db_get_new_image($value)
{
			$keys = 'order_'.$value;
			$new = get_option($keys);
			if(!$new || intval($new)==0)
				$new = '<img alt="" src="'.get_bloginfo('template_url').'/images/new.jpg"';
			else 
				$new = '';
				return $new;	
}
